#!/bin/sh
#
# FUCTION： 生成每本书，每章对应的字典。
#

if [ $# -ne 0 ]; then
	echo "Usage: I do not need args"
	exit
fi

if [ ! -e config ]; then
	echo "no config file"
	exit -1
fi

source config


indexfile="dicts/index.md"

echo "% $bookname 的字典" > $indexfile

echo "" >>$indexfile

for files in `ls dicts/dict.*.md`
do
	chaptername=`echo $files |sed -e "s/\.md//g"`
	htmlname=$chaptername.html
	chapter=`echo $chaptername|sed -e "s/.*_//g"`
	echo "% $bookname 第" $chapter "章字典" >tmp.md

	echo "" >>tmp.md 

	commcode bookheader >>tmp.md 

	echo "" >>tmp.md 

	cat $files >>tmp.md 

	pandoc -s tmp.md -o $htmlname

	echo "[$bookname 第 $chapter 章字典]($htmlname)"  |sed -e "s/dicts/\./g">>$indexfile

	echo "" >>$indexfile

done

pandoc -s $indexfile -o dicts/index.html

mv dicts/*.html $basedir$url/dicts/

rm -f tmp.md 